package cn.btks.backstagemanage.division.controller;

import cn.btks.backstagemanage.division.pojo.County;
import cn.btks.backstagemanage.division.service.CountyService;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/1/25 11:09
 */
@RestController
@RequestMapping("api/v1.0/unit")
@Api(tags = "行政区划模块")
@Validated
public class CountyController {

    @Autowired
    CountyService countyService;

    @GetMapping("/find/county/findAll")
    @ApiOperation("查询所有团场区划信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<County> countyList = countyService.findAll();
        return countyList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), countyList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/find/county/findAllByCityId/{cityId}")
    @ApiOperation("查询所有师下的所有团场区划信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "cityId", value = "师ID", required = true, dataType = "long"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByCityId(@PathVariable("cityId") Long cityId) {
        List<County> countyList = countyService.findAllByCityId(cityId);
        return countyList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), countyList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/find/county/findAllByEscrowId/{cityId}")
    @ApiOperation("根据代管师的ID查询其代管团场")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "cityId", value = "师ID", required = true, dataType = "long"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByEscrowId(@PathVariable("cityId") Long cityId) {
        List<County> countyList = countyService.findAllByEscrowId(cityId);
        return countyList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), countyList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
